﻿#ifndef DOCKWIDGETTSC_H
#define DOCKWIDGETTSC_H

#include <QDockWidget>
#include <QSerialPort>
#include <QFile>
#include <QProgressDialog>

class ConfirmDevice;
class DockWidgetCTD_IMCharts;

namespace Ui {
class DockWidgetCTD;
}

class DockWidgetCTD : public QDockWidget
{
    Q_OBJECT

public:
    explicit DockWidgetCTD(QWidget *parent = nullptr);
    ~DockWidgetCTD();
    QSerialPort serialPortCTD;

    void sendBaudAndPortName(int,const QString &);

    void closeDockWidgetDeal();
private slots:
    void on_m_combomBox_Coefficient_currentIndexChanged(int index);

    void on_pushButton_3_clicked();

    void on_m_Button_SyncLocalTime_clicked();

    void on_getStatusButton_clicked();

    void on_saveTransFormat_clicked();

    void on_saveRealtimeTransfer_clicked();

    void on_saveStorage_clicked();

    void on_saveBaudRate_clicked();

    void on_getConfig_clicked();

    void on_clearMemory_clicked();

    void on_m_radioButton_Hour_clicked(bool checked);

    void on_m_radioButton_Minute_clicked(bool checked);

    void on_m_radioButton_Second_clicked(bool checked);

    void on_pushButtonStartSample_clicked();

    void on_mUseLastConfig_clicked();

    void on_mCTDIMDownLoad_clicked();

    void on_m_CalibrationCoefficient_clicked();

    void on_m_PtnSaveCoefficient_clicked();

protected:
    //void closeEvent(QCloseEvent* event) override;


private:
    Ui::DockWidgetCTD*ui;
    QByteArray readCTDAll;
    QString T1, T2, T3, T4, Pressure, P1, P2, P3, P4, Poffset, Latitude, C1, C2, C3, C4;
    QTimer* m_timerCTD;
    bool isStartSample = true, CTDIMDownLoad = false;
    QFile m_clsFile;
    int m_iSamplingCount=0, m_iSamplesQuantity=0;
    QProgressDialog* m_pBar = nullptr;

    bool SetSerialPortParam(QSerialPort* serial, int Baudrate, QByteArray serialCommand);
    void readResponseCTD();
    void initConfigCTD_IM();
    void setChangeStatus(bool);

    void setCalibrationCoefficientTemperatureTable();
    void setCalibrationCoefficientPressureTable();
    void setCalibrationCoefficientConductivityTable();
    void sendCommand(QByteArray& data);

    void dealTableE11();
    void dealTableE12();
    void dealTableE13();

    void dealTableE21();
    void dealTableE22();
    void dealTableE23();

    void dealTableE31();
    void dealTableE32();
    void dealTableE33();
signals:
    // connect 在dockwidgetctd_imcharts.cpp里面写着，避免循环引用
    void sendOnceSample(QByteArray&);
    void sendChangeStatus(bool);

public slots:
    void recvChangeStatus(bool flag);
};


#define DockWidgetCTDRelease Singleton<DockWidgetCTD>::Release()
#define DockWidgetCTDInstance Singleton<DockWidgetCTD>::GetInstance()


#endif // DOCKWIDGETTSC_H
